package com.itheima.edu.info.maneger.dao;

import com.itheima.edu.info.maneger.domain.Student;
import com.itheima.edu.info.maneger.domain.Teacher;

import java.util.ArrayList;

public class OtherTeacherDao implements BaseTeacherDao{
    //1.创建Teacher学生数组长度为5
    private static ArrayList<Teacher> stus = new ArrayList<>();

    static {
        Teacher teacher = new Teacher("0001", "张三", 23, "1991");
        Teacher teacher2 = new Teacher("0002", "李四", 24, "1996");
        Teacher teacher3 = new Teacher("0003", "王五", 25, "1992");
        Teacher teacher4 = new Teacher("0004", "赵六", 23, "1994");

        stus.add(teacher);
        stus.add(teacher2);
        stus.add(teacher3);
        stus.add(teacher4);

    }
    //查找所有老师
    public Teacher[] findAllTeacher() {
        Teacher[] teachers = new Teacher[stus.size()];
        for (int i = 0; i < stus.size(); i++) {
            teachers[i] = stus.get(i);
        }
        return teachers;
    }


    //添加老师
    public boolean addTeacher(Teacher teacher) {
        stus.add(teacher);
        return true;
    }
    //删除老师
    public void deleteTeacher(String id) {
        int index = getIndex(id);
        stus.remove(index);
    }
    //获取id
    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < stus.size(); i++) {
            Teacher teacher = stus.get(i);
            if (teacher != null && teacher.getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    //修改老师
    public void updateTeacher(String updateId, Teacher newteacher) {
        int index = getIndex(updateId);
        stus.set(index,newteacher);
    }
}
